package cn.moukou.dictator.util;

import cn.moukou.dictator.pojo.ClassRoom;
import cn.moukou.dictator.pojo.Teacher;
import org.neo4j.ogm.typeconversion.CompositeAttributeConverter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ClassRoomConverter implements CompositeAttributeConverter<ClassRoom> {

    @Override
    public Map<String, ?> toGraphProperties(ClassRoom entity) {
        Map<String, Object> properties = new HashMap<>();
        if (entity != null)  {
            properties.put("class_name", entity.getName());
            properties.put("class_location", entity.getLocation());
            properties.put("class_award_list", entity.getAwardList());

        }
        return properties;
    }

    @Override
    public ClassRoom toEntityAttribute(Map<String, ?> map) {
        if(!map.get("node_type").toString().equals("class_room")) {
            return null;
        }
        ClassRoom entity = new ClassRoom();
        entity.setName((String) map.get("class_name"));
        entity.setLocation((String) map.get("class_location"));
        entity.setAwardList((List<String>) map.get("class_award_list"));

        return entity;
    }
}
